package com.spzx.order.message;

import com.rabbitmq.client.Channel;
import com.spzx.common.rabbit.constant.MqConst;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Component
public class ReceiveMessage {



    @RabbitListener(bindings = @QueueBinding(
            exchange =@Exchange(value = MqConst.EXCHANGE_TEST,durable = "true"),
            value = @Queue(value = MqConst.QUEUE_TEST),
            key = MqConst.ROUTING_TEST
    ))
    public void receiveMessage(String msg, Message message, Channel channel) throws IOException {
        System.out.println("message = " + msg);

        // false 确认一个消息，true 批量确认
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

}
